package br.com.senacrs.dao;

import br.com.senacrs.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class DaoFactory {
    
    private final Session session;
    private Transaction transaction;

    public DaoFactory() {
        this.session = HibernateUtil.getSession();
    }

    public void beginTransaction() {
        this.transaction = this.session.beginTransaction();
    }

    public void commit() {
        this.transaction.commit();
        this.transaction = null;
    }

    public boolean hasTransaction() {
        return this.transaction != null;
    }

    public void rollback() {
        this.transaction.rollback();
        this.transaction = null;
    }

    public void close() {
        this.session.close();
    }
    
    public UsuarioDao getUsuarioDao(){
		return new UsuarioDao(this.session); 
	}
    
    public SistemaDao getSistemaDao(){
		return new SistemaDao(this.session); 
	}
    
    public UsuarioSistemaDao getUsuarioSistemaDao(){
		return new UsuarioSistemaDao(this.session); 
	}
    
    public EstadoDao getEstadoDao(){
		return new EstadoDao(this.session); 
	}
    
    public CidadeDao getCidadeDao(){
		return new CidadeDao(this.session); 
	}
    
}
